<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="div1">点我绑定事件</div>
    <script>
      var addEvent = function (elem, type, handler) {
        if (window.addEventListener) {
          addEvent = function (elem, type, handler) {
            elem.addEventListener(type, handler, false);
          };
        } else if (window.attachEvent) {
          addEvent = function (elem, type, handler) {
            elem.attachEvent("on" + type, handler);
          };
        }

        addEvent(elem, type, handler);
      };
      var div = document.getElementById("div1");

      addEvent(div, "click", function () {
        alert(1);
      });

      addEvent(div, "click", function () {
        alert(2);
      });
    </script>
  </body>
</html>
